﻿$(function () {
    $("#ddlPatientList").ligerComboBox({
        width: 140,
        cancelable: false,
        valueField: "PATIENT_ID",
        textField: "PATIENT_NAME",
        valueFieldID: 'hdnPatientId',
        onSelected: function (value, text) {
            search();
        }
    });
    getPatientList();
});

function getPatientList() {
    $.ajax({
        url: "/StrokeCenter/PatientList/GetPatientList?ram" + Math.random(),
        type: "Post",
        data: {},
        success: function (result) {
            var jsonResult = $.parseJSON(result);
            if (jsonResult.Result == 1) {
                var jsonData = $.parseJSON(jsonResult.Body).PatientList;
                for (var i = 0; i < jsonData.length; i++) {
                    jsonData[i].PATIENT_NAME = jsonData[i].PATIENT_NAME + "   " + (jsonData[i].PATIENT_SEX == 1 ? "男" : jsonData[i].PATIENT_SEX == 0 ? "女" : "") + "    " + (IsEmpty(jsonData[i].PATIENT_AGE) ? "" : jsonData[i].PATIENT_AGE + "岁");
                }
            }
            $("#ddlPatientList").ligerComboBox({ data: jsonData });
            $("#ddlPatientList").ligerComboBox().setValue(jsonData[0].PATIENT_ID);

            $(".l-box-select-table").find("tr").each(function () {
                var reg = new RegExp(" ", "g");
                $(this).children('td').eq(0).first("span").html($(this).children('td').eq(0).first("span").html().replace(reg, "&nbsp;"));
            });
        },
        error: function () {
            $.ligerDialog.error("程序错误");
        }
    });
}

function search(pageNumber) {
    var queryData = {
        triageId: $("#hdnPatientId").val()
    }
    initTable(queryData, 1);
}

function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        checkbox: false,
        height: '100%',
        url: '/InspectionReport/Search?ram=' + new Date().getMilliseconds(),
        parms: queryData,
        page: pageNumber,
        usePager: false,
        rownumbers: false,
        fixedCellHeight: false,
        isScroll: true,
        heightDiff: 20,
        columns: [
            { display: '姓名', name: 'PTN_NAME', width: 80 },
            { display: '性别', name: 'SEX', width: 50, render: function (row) { return row.SEX == "F" ? "女" : "男"; } },
            { display: '病案号', name: 'PatientID', width: 120 },
            { display: '报告单', name: 'ReportSmallTile', width: 120 },
            { display: '科室名称', name: 'ReqDepartment', width: 100 },
            { display: '医生', name: 'ReqPhysician', width: 70 },
            {
                display: '申请时间', name: 'ReqDate', width: 80, render: function (row) {
                    return row.ReqDate.substring(0, 4) + "-" + row.ReqDate.substring(4, 6) + "-" + row.ReqDate.substring(6, 8) + "<br/>" + row.ReqTime.substring(0, 2) + ":" + row.ReqTime.substring(2, 4) + ":" + row.ReqTime.substring(4, 6);
                }
            },
            {
                display: '检查时间', name: 'ExamDate', width: 80, render: function (row) {
                    return row.ExamDate.substring(0, 4) + "-" + row.ExamDate.substring(4, 6) + "-" + row.ExamDate.substring(6, 8) + "<br/>" + row.ExamTime.substring(0, 2) + ":" + row.ExamTime.substring(2, 4) + ":" + row.ExamTime.substring(4, 6);
                }
            },
            {
                display: '患者类别', name: 'PatientTypeID', width: 70, render: function (row) {
                    if (row.PatientTypeID == 0) {
                        return "门诊";
                    }
                    else if (row.PatientTypeID == 1) {
                        return "住院";
                    }
                    else if (row.PatientTypeID == 1) {
                        return "体检";
                    }
                }
            },
            { display: '检查方式', name: 'ModalityType', width: 70 },
            { display: '检查描述', name: 'EaxmDesc', width: 100 },
            {
                display: '影像所见', name: 'ImageFinding', minWidth: 200, align: 'left', render: function (row) {
                    return "<div style=\"white-space:pre-wrap;\">" + row.ImageFinding + "</div>";
                }
            },
            {
                display: '检查结果描述', name: 'Impression', minWidth: 200, align: 'left', render: function (row) {
                    return "<div style=\"white-space:pre-wrap;\">" + row.Impression + "</div>";
                }
            },
            { display: '报告人员', name: 'WriteUserName', width: 80 },
            { display: '校验人员', name: 'VERTUserName', width: 80 },
            {
                display: '影像地址', name: 'ImagePTNIDURL', width: 80, render: function (row) {
                    return "<a href=\"" + row.ImagePTNIDURL + "\">图片</a>";
                }
            }
        ]
    });
    GridNoData($("#maingrid"));
}